package processs;

import example.demo_navi.R;
import gui_View.Playlistview;

import java.util.ArrayList;

import clicks.Listvideoclick;

import models.Listvid;
import utility.DbConnect;
import videos.Main2;
import android.app.Fragment;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class Navi_draw6 extends Fragment{

	private Playlistview pl;
	public static final String ARG_NUMBER="position";
	private DbConnect dbc;
	private String lida;
	ArrayList<Listvid> al;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		dbc=new DbConnect(getActivity().getApplicationContext());
		al=new ArrayList<Listvid>();
		View v=inflater.inflate(R.layout.activity_main, container, false);
		pl=(Playlistview) v.findViewById(R.id.videosListView);
		pl.setonPlistvi(new xuli());
	//	int i=getArguments().getInt(ARG_NUMBER);
	//	String s=getArguments().getString("chara");
		String[] mni=getResources().getStringArray(R.array.Cate_video);
	//	getActivity().getActionBar().setTitle(mni[i]);
		new Get3q().execute();
		return v;
	}
	
	private class Get3q extends AsyncTask<Void, Void, Void>{

		private ProgressDialog pd;
		
		@Override
		protected Void doInBackground(Void... arg0) {
			// TODO Auto-generated method stub
			dbc.opend();
			al=dbc.getAllPlaylist_3(5);
			for(int i=0;i<al.size();i++){
				Listvid vi=al.get(i);
				lida=vi.getLid();
				String titi=vi.getLiti();
				String thumb=vi.getLithum();
			}
			
			return null;
		}

		@Override
		protected void onPostExecute(Void result) {
			// TODO Auto-generated method stub
			pd.dismiss();
			pl.setPlaylist(al);
		}

		@Override
		protected void onPreExecute() {
			// TODO Auto-generated method stub
			pd=new ProgressDialog(getActivity());
			pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
			pd.setMessage("Loading Playlists...");
			pd.show();
		}
		
	}
	
	private class xuli implements Listvideoclick{

		public void onListvidClicked(Listvid lv) {
			// TODO Auto-generated method stub
			Intent in=new Intent(getActivity().getApplicationContext(), Main2.class);
			in.setData(Uri.parse(lv.getLid()));
		//	in.putExtra("holle", lv.getLid());
			Log.d("tester", lv.getLid());
			startActivity(in);
		}		
	}
}
